/*     */ package me.wazup.kitbattle;
/*     */ 
/*     */ import java.sql.ResultSet;
/*     */ import java.sql.SQLException;
/*     */ import java.sql.Statement;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Random;
/*     */ import org.bukkit.Bukkit;
/*     */ import org.bukkit.ChatColor;
/*     */ import org.bukkit.Color;
/*     */ import org.bukkit.Effect;
/*     */ import org.bukkit.FireworkEffect;
/*     */ import org.bukkit.Location;
/*     */ import org.bukkit.Material;
/*     */ import org.bukkit.Sound;
/*     */ import org.bukkit.block.BlockFace;
/*     */ import org.bukkit.block.Sign;
/*     */ import org.bukkit.command.CommandSender;
/*     */ import org.bukkit.entity.EntityType;
/*     */ import org.bukkit.entity.Firework;
/*     */ import org.bukkit.entity.Player;
/*     */ import org.bukkit.event.EventHandler;
/*     */ import org.bukkit.event.Listener;
/*     */ import org.bukkit.event.block.Action;
/*     */ import org.bukkit.event.block.BlockBreakEvent;
/*     */ import org.bukkit.event.block.BlockPlaceEvent;
/*     */ import org.bukkit.event.block.SignChangeEvent;
/*     */ import org.bukkit.event.entity.EntityDamageEvent;
/*     */ import org.bukkit.event.entity.FoodLevelChangeEvent;
/*     */ import org.bukkit.event.entity.PlayerDeathEvent;
/*     */ import org.bukkit.event.inventory.InventoryClickEvent;
/*     */ import org.bukkit.event.player.AsyncPlayerChatEvent;
/*     */ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
/*     */ import org.bukkit.event.player.PlayerDropItemEvent;
/*     */ import org.bukkit.event.player.PlayerInteractEntityEvent;
/*     */ import org.bukkit.event.player.PlayerInteractEvent;
/*     */ import org.bukkit.event.player.PlayerJoinEvent;
/*     */ import org.bukkit.event.player.PlayerLoginEvent;
/*     */ import org.bukkit.event.player.PlayerMoveEvent;
/*     */ import org.bukkit.event.player.PlayerPickupItemEvent;
/*     */ import org.bukkit.event.player.PlayerQuitEvent;
/*     */ import org.bukkit.inventory.Inventory;
/*     */ import org.bukkit.inventory.InventoryHolder;
/*     */ import org.bukkit.inventory.ItemStack;
/*     */ import org.bukkit.inventory.meta.FireworkMeta;
/*     */ import org.bukkit.plugin.Plugin;
/*     */ import org.bukkit.potion.PotionEffect;
/*     */ import org.bukkit.scheduler.BukkitRunnable;
/*     */ import org.bukkit.scheduler.BukkitTask;
/*     */ import org.bukkit.scoreboard.DisplaySlot;
/*     */ import org.bukkit.scoreboard.Objective;
/*     */ import org.bukkit.scoreboard.Scoreboard;
/*     */ import org.bukkit.util.Vector;
/*     */ 
/*     */ public class listener
/*     */   implements Listener {
/*     */   String kb;
/*     */   private main plugin;
/*  61 */   Random random = new Random();
/*     */ 
/*     */   
/*     */   ItemStack yes;
/*     */ 
/*     */   
/*     */   ItemStack no;
/*     */   
/*     */   ItemStack soup;
/*     */ 
/*     */   
/*     */   public listener(main plugin, String kb) {
/*  73 */     this.soup = new ItemStack(Material.MUSHROOM_SOUP);
/*     */     this.plugin = plugin;
/*     */     this.kb = kb;
/*     */     this.yes = plugin.setName(new ItemStack(Material.WOOL, 1, (short)5), ChatColor.GREEN + "Yes!");
/*  77 */     this.no = plugin.setName(new ItemStack(Material.WOOL, 1, (short)14), ChatColor.RED + "No!"); } @EventHandler public void onPlayerBreakBlock(BlockBreakEvent e) { if (e.isCancelled())
/*  78 */       return;  Player p = e.getPlayer();
/*  79 */     Material type = e.getBlock().getType();
/*  80 */     if (type.equals(Material.SIGN) || type.equals(Material.SIGN_POST) || type.equals(Material.WALL_SIGN)) {
/*  81 */       Sign s = (Sign)e.getBlock().getState();
/*  82 */       if (s.getLine(0).equals(this.plugin.config.SignsPrefix)) {
/*  83 */         if (!p.hasPermission("kitbattle.breaksigns")) {
/*  84 */           p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.nopermission);
/*  85 */           e.setCancelled(true);
/*     */           
/*     */           return;
/*     */         } 
/*     */         
/*  90 */         int rank = Integer.valueOf(s.getLine(2).replace("#", "").split(" ")[0]).intValue();
/*  91 */         if (s.getLine(1).equals("Top") && this.plugin.isNumber(s.getLine(2).replace("#", "").split(" ")[0]) && this.plugin.fileManager.getSignsConfig().contains("Top." + rank)) {
/*  92 */           this.plugin.fileManager.getSignsConfig().set("Top." + rank, null);
/*  93 */           this.plugin.fileManager.saveSignsConfig();
/*  94 */           p.sendMessage(String.valueOf(this.kb) + "You have broken a top sign!");
/*  95 */           this.plugin.fixUpdater();
/*     */         } 
/*     */       } 
/*     */     } 
/*     */ 
/*     */     
/* 101 */     if (this.plugin.game.contains(p.getName())) {
/* 102 */       e.setCancelled(true);
/*     */     } }
/*     */ 
/*     */   
/*     */   @EventHandler
/*     */   public void onPlayerBlockPlace(BlockPlaceEvent e) {
/* 108 */     Player p = e.getPlayer();
/* 109 */     if (this.plugin.game.contains(p.getName())) {
/* 110 */       e.setCancelled(true);
/*     */     }
/*     */   }
/*     */   
/*     */   @EventHandler
/*     */   public void onPlayerLogin(PlayerLoginEvent e) {
/* 116 */     if (this.plugin.config.BungeeMode && 
/* 117 */       this.plugin.currentMap == null) {
/* 118 */       e.disallow(PlayerLoginEvent.Result.KICK_OTHER, String.valueOf(this.kb) + this.plugin.msgs.NoAvailableMaps);
/*     */       return;
/*     */     } 
/*     */   }
/*     */ 
/*     */   
/*     */   @EventHandler
/*     */   public void onPlayerJoin(PlayerJoinEvent e) {
/* 126 */     final Player p = e.getPlayer();
/* 127 */     this.plugin.playerData.put(p.getName(), new PlayerData(p, this.plugin));
/* 128 */     if (this.plugin.config.BungeeMode) {
/* 129 */       p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.PlayerJoinMap.replace("%map%", this.plugin.currentMap));
/* 130 */       this.plugin.game.add(p.getName());
/* 131 */       p.teleport(this.plugin.maps.get(this.plugin.currentMap));
/* 132 */       ((PlayerData)this.plugin.playerData.get(p.getName())).saveData(p, this.plugin.currentMap);
/* 133 */       this.plugin.clearData(p);
/* 134 */       Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin)this.plugin, new Runnable() {
/*     */             public void run() {
/* 136 */               if (p != null) {
/*     */                 try {
/* 138 */                   listener.this.plugin.giveDefaultItems(p);
/* 139 */                   listener.this.plugin.createScoreboard(p);
/* 140 */                 } catch (Exception e) {
/* 141 */                   listener.this.plugin.logger.info("[KitBattle] Couldn't create a scoreboard for the player " + p.getName() + "! the player stats probably didn't load quickly enough");
/*     */                 } 
/*     */               }
/*     */             }
/* 145 */           },  5L);
/*     */     } 
/*     */   }
/*     */   
/*     */   @EventHandler
/*     */   public void onPlayerLeave(PlayerQuitEvent e) {
/* 151 */     Player p = e.getPlayer();
/* 152 */     if (this.plugin.game.contains(p.getName())) {
/* 153 */       this.plugin.leave(p);
/*     */     }
/* 155 */     ((PlayerData)this.plugin.playerData.get(p.getName())).saveStatsIntoFile(p, false);
/* 156 */     this.plugin.playerData.remove(p.getName());
/*     */   }
/*     */   
/*     */   @EventHandler
/*     */   public void onPlayerDeath(PlayerDeathEvent e) {
/* 161 */     final Player p = e.getEntity();
/* 162 */     if (this.plugin.game.contains(p.getName())) {
/* 163 */       p.setHealth(20.0D);
/* 164 */       p.closeInventory();
/* 165 */       final boolean isAPlayer = (p.getKiller() != null && p.getKiller() instanceof Player);
/* 166 */       if (this.plugin.config.DoPlayersDropItemsOnDeath) {
/* 167 */         for (ItemStack ItemStack : e.getDrops()) {
/* 168 */           p.getWorld().dropItemNaturally(p.getLocation(), ItemStack);
/*     */         }
/*     */       }
/* 171 */       e.setDeathMessage(null);
/* 172 */       e.getDrops().clear();
/* 173 */       p.getInventory().clear();
/* 174 */       p.getInventory().setArmorContents(null);
/* 175 */       p.setFallDistance(0.0F);
/* 176 */       p.setAllowFlight(false);
/* 177 */       p.teleport(this.plugin.maps.get(((PlayerData)this.plugin.playerData.get(p.getName())).getMap()));
/* 178 */       ((PlayerData)this.plugin.playerData.get(p.getName())).addDeaths();
/* 179 */       ((PlayerData)this.plugin.playerData.get(p.getName())).setKit(null);
/* 180 */       ((PlayerData)this.plugin.playerData.get(p.getName())).killstreak = 0;
/*     */       
/* 182 */       String DeathMessage = "";
/* 183 */       if (!isAPlayer)
/* 184 */       { if (p.getLastDamageCause() == null) {
/* 185 */           DeathMessage = String.valueOf(this.kb) + this.plugin.msgs.unknownMessage.replaceAll("%player%", p.getName());
/*     */         } else {
/* 187 */           EntityDamageEvent.DamageCause cause = p.getLastDamageCause().getCause();
/* 188 */           if (cause.equals(EntityDamageEvent.DamageCause.FALL)) {
/* 189 */             DeathMessage = String.valueOf(this.kb) + this.plugin.msgs.fallMessage.replaceAll("%player%", p.getName());
/*     */           }
/* 191 */           else if (cause.equals(EntityDamageEvent.DamageCause.LAVA)) {
/* 192 */             DeathMessage = String.valueOf(this.kb) + this.plugin.msgs.lavaMessage.replaceAll("%player%", p.getName());
/*     */           }
/* 194 */           else if (cause.equals(EntityDamageEvent.DamageCause.FIRE) || cause.equals(EntityDamageEvent.DamageCause.FIRE_TICK)) {
/* 195 */             DeathMessage = String.valueOf(this.kb) + this.plugin.msgs.fireMessage.replaceAll("%player%", p.getName());
/*     */           }
/* 197 */           else if (cause.equals(EntityDamageEvent.DamageCause.ENTITY_EXPLOSION) || cause.equals(EntityDamageEvent.DamageCause.BLOCK_EXPLOSION)) {
/* 198 */             DeathMessage = String.valueOf(this.kb) + this.plugin.msgs.explodeMessage.replaceAll("%player%", p.getName());
/*     */           } else {
/* 200 */             DeathMessage = String.valueOf(this.kb) + this.plugin.msgs.unknownMessage.replaceAll("%player%", p.getName());
/*     */           } 
/*     */         }  }
/* 203 */       else { DeathMessage = String.valueOf(this.kb) + ((String)this.plugin.msgs.killMessages.get(this.plugin.random.nextInt(this.plugin.msgs.killMessages.size()))).replaceAll("%player%", p.getName()).replaceAll("%killer%", p.getKiller().getName()); }
/*     */ 
/*     */       
/* 206 */       int previousExp = 0;
/* 207 */       int previousCoins = 0;
/* 208 */       int previousRequiredExp = 0;
/* 209 */       if (this.plugin.Fighting.containsKey(p.getName())) {
/* 210 */         Player killer = Bukkit.getPlayer(this.plugin.Challenging.get(p.getName()));
/* 211 */         killer.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.PlayerWinChallenge);
/* 212 */         p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.PlayerLoseChallenge.replace("%killer%", killer.getName()));
/* 213 */         DeathMessage = String.valueOf(DeathMessage) + ChatColor.YELLOW + " " + ChatColor.UNDERLINE + "in a 1v1";
/* 214 */         removeFromChallenge(p);
/* 215 */         for (String cmd : this.plugin.config.commandsExecutedForChallengeLoser) {
/* 216 */           Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), cmd.replace("%player%", p.getName()));
/*     */         }
/* 218 */         removeFromChallenge(killer);
/* 219 */         for (String cmd : this.plugin.config.commandsExecutedForChallengeWinner) {
/* 220 */           Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), cmd.replace("%player%", killer.getName()));
/*     */         }
/*     */       } 
/* 223 */       if (isAPlayer) {
/* 224 */         Player killer = p.getKiller();
/* 225 */         if (killer.getName() != p.getName()) {
/* 226 */           PlayerData data = this.plugin.playerData.get(killer.getName());
/* 227 */           data.killstreak++;
/* 228 */           killer.setLevel(data.killstreak);
/* 229 */           if (this.plugin.config.Killstreaks.containsKey(Integer.valueOf(data.killstreak))) {
/* 230 */             killer.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.PlayerGetKillstreakSelfMessage.replace("%kills%", String.valueOf(data.killstreak)));
/* 231 */             if (this.plugin.config.SendKillstreaksToEveryone) {
/* 232 */               String message = String.valueOf(this.kb) + this.plugin.msgs.PlayerGetKillstreakAnnouncement.replace("%player%", killer.getName()).replace("%kills%", String.valueOf(data.killstreak));
/* 233 */               for (String a : this.plugin.game) {
/* 234 */                 Bukkit.getPlayer(a).sendMessage(message);
/*     */               }
/*     */             } 
/* 237 */             for (String command : this.plugin.config.Killstreaks.get(Integer.valueOf(data.killstreak))) {
/* 238 */               Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), command.replace("%player%", killer.getName()));
/*     */             }
/*     */           } 
/* 241 */           previousExp = data.getExp();
/* 242 */           previousCoins = this.plugin.getCoins(killer);
/* 243 */           previousRequiredExp = (data.getNextRank() == null) ? 0 : (data.getNextRank().getRequiredExp() - previousExp);
/* 244 */           boolean isVip = killer.hasPermission("kitbattle.vip");
/* 245 */           int earnedCoins = isVip ? (this.plugin.config.EarnedCoinsPerKill * 2) : this.plugin.config.EarnedCoinsPerKill;
/* 246 */           data.addKills();
/* 247 */           this.plugin.addCoins(killer, earnedCoins);
/* 248 */           int earnedExp = isVip ? (((Integer)this.plugin.config.possibleExp.get(this.random.nextInt(this.plugin.config.possibleExp.size()))).intValue() * 2) : ((Integer)this.plugin.config.possibleExp.get(this.random.nextInt(this.plugin.config.possibleExp.size()))).intValue();
/* 249 */           data.addExp(earnedExp);
/* 250 */           p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.PlayerDeathMessage.replace("%killer%", killer.getName()));
/* 251 */           killer.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.PlayerKillMessage.replace("%player%", p.getName()).replace("%coins%", String.valueOf(earnedCoins)).replace("%exp%", String.valueOf(earnedExp)) + (isVip ? (ChatColor.GRAY + " (" + ChatColor.AQUA + "x2" + ChatColor.GRAY + ")!") : ""));
/*     */         } else {
/* 253 */           p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.PlayerSuicideMessage);
/*     */         } 
/*     */       } 
/* 256 */       if (this.plugin.config.SendDeathMessageToEveryone) {
/* 257 */         for (String x : this.plugin.game) {
/* 258 */           Bukkit.getPlayer(x).sendMessage(DeathMessage);
/*     */         }
/*     */       }
/* 261 */       final int finalPreviousCoins = previousCoins;
/* 262 */       final int finalPreviousExp = previousExp;
/* 263 */       final int finalPreviousRequiredExp = previousRequiredExp;
/* 264 */       Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin)this.plugin, new Runnable() {
/*     */             public void run() {
/* 266 */               listener.this.plugin.giveDefaultItems(p);
/* 267 */               p.setFireTicks(0);
/* 268 */               p.setLevel(0);
/* 269 */               p.setExp(0.0F);
/* 270 */               p.setFoodLevel(20);
/* 271 */               for (PotionEffect effect : p.getActivePotionEffects()) {
/* 272 */                 p.removePotionEffect(effect.getType());
/*     */               }
/*     */               try {
/* 275 */                 Scoreboard board = p.getScoreboard();
/* 276 */                 if (board.getObjective(DisplaySlot.SIDEBAR) == null || !board.getObjective(DisplaySlot.SIDEBAR).getDisplayName().equals(ChatColor.YELLOW + ChatColor.BOLD + ChatColor.UNDERLINE + "KitBattle")) {
/* 277 */                   listener.this.plugin.createScoreboard(p);
/*     */                 } else {
/* 279 */                   Objective obj = board.getObjective(DisplaySlot.SIDEBAR);
/* 280 */                   board.resetScores(listener.this.plugin.msgs.scoreboard_deaths.replace("%deaths%", String.valueOf(((PlayerData)listener.this.plugin.playerData.get(p.getName())).getDeaths() - 1)));
/* 281 */                   obj.getScore(listener.this.plugin.msgs.scoreboard_deaths.replace("%deaths%", String.valueOf(((PlayerData)listener.this.plugin.playerData.get(p.getName())).getDeaths()))).setScore(2);
/*     */                 } 
/* 283 */               } catch (Exception x) {
/* 284 */                 x.printStackTrace();
/* 285 */                 listener.this.plugin.logger.info("[KitBattle] Error has occured while creating/updating the player: " + p.getName() + " scoreboard!");
/*     */               } 
/* 287 */               if (isAPlayer) {
/* 288 */                 Player killer = p.getKiller();
/* 289 */                 if (p.getName().equals(killer.getName()))
/* 290 */                   return;  boolean rankedup = listener.this.checkRankUp(killer, finalPreviousRequiredExp);
/*     */                 try {
/* 292 */                   Scoreboard board = killer.getScoreboard();
/* 293 */                   if (board.getObjective(DisplaySlot.SIDEBAR) == null || !board.getObjective(DisplaySlot.SIDEBAR).getDisplayName().equals(ChatColor.YELLOW + ChatColor.BOLD + ChatColor.UNDERLINE + "KitBattle")) {
/* 294 */                     listener.this.plugin.createScoreboard(killer);
/*     */                   } else {
/* 296 */                     Objective obj = board.getObjective(DisplaySlot.SIDEBAR);
/* 297 */                     PlayerData data = listener.this.plugin.playerData.get(killer.getName());
/* 298 */                     board.resetScores(listener.this.plugin.msgs.scoreboard_coins.replace("%coins%", String.valueOf(finalPreviousCoins)));
/* 299 */                     obj.getScore(listener.this.plugin.msgs.scoreboard_coins.replace("%coins%", String.valueOf(listener.this.plugin.getCoins(killer)))).setScore(1);
/* 300 */                     board.resetScores(listener.this.plugin.msgs.scoreboard_kills.replace("%kills%", String.valueOf(data.getKills() - 1)));
/* 301 */                     obj.getScore(listener.this.plugin.msgs.scoreboard_kills.replace("%kills%", String.valueOf(data.getKills()))).setScore(3);
/* 302 */                     board.resetScores(listener.this.plugin.msgs.scoreboard_exp.replace("%exp%", String.valueOf(finalPreviousExp)));
/* 303 */                     obj.getScore(listener.this.plugin.msgs.scoreboard_exp.replace("%exp%", String.valueOf(data.getExp()))).setScore(-1);
/* 304 */                     if (!rankedup && data.getNextRank() != null) {
/* 305 */                       board.resetScores(listener.this.plugin.msgs.scoreboard_nextrankname.replace("%requiredexp%", String.valueOf(finalPreviousRequiredExp)));
/* 306 */                       obj.getScore(listener.this.plugin.msgs.scoreboard_nextrankname.replace("%requiredexp%", String.valueOf(data.getNextRank().getRequiredExp() - data.getExp()))).setScore(-5);
/*     */                     } 
/*     */                   } 
/* 309 */                 } catch (Exception x) {
/* 310 */                   x.printStackTrace();
/* 311 */                   listener.this.plugin.logger.info("[KitBattle] Error has occured while creating/updating the player: " + killer.getName() + " scoreboard!");
/*     */                 } 
/*     */               } 
/*     */             }
/* 315 */           }2L);
/*     */     } 
/*     */   }
/*     */   
/*     */   @EventHandler
/*     */   public void onPlayerPickupItem(PlayerPickupItemEvent e) {
/* 321 */     if (this.plugin.game.contains(e.getPlayer().getName()) && !this.plugin.config.CanPlayersPickItemsOnGround) {
/* 322 */       e.setCancelled(true);
/*     */     }
/*     */   }
/*     */   
/*     */   @EventHandler
/*     */   public void onPlayerDropItem(final PlayerDropItemEvent e) {
/* 328 */     if (this.plugin.game.contains(e.getPlayer().getName()) && !this.plugin.config.CanPlayersDropItemsOnGround) {
/* 329 */       if (e.getItemDrop().getItemStack().getType().equals(Material.BOWL)) {
/* 330 */         e.getPlayer().playSound(e.getPlayer().getLocation(), this.plugin.config.dropSound, 1.0F, 1.0F);
/* 331 */         Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin)this.plugin, new Runnable() {
/*     */               public void run() {
/* 333 */                 e.getItemDrop().remove();
/*     */               }
/* 335 */             },  20L);
/*     */       } else {
/* 337 */         e.setCancelled(true);
/*     */       } 
/*     */     }
/*     */   }
/*     */   
/*     */   @EventHandler
/*     */   public void onFoodLevelChange(FoodLevelChangeEvent e) {
/* 344 */     if (this.plugin.game.contains(e.getEntity().getName()) && !this.plugin.config.DoPlayersLoseHunger) {
/* 345 */       e.setCancelled(true);
/*     */     }
/*     */   }
/*     */   
/*     */   @EventHandler
/*     */   public void onPlayerInteract(PlayerInteractEvent e) {
/* 351 */     final Player p = e.getPlayer();
/* 352 */     if (e.getAction().equals(Action.RIGHT_CLICK_BLOCK) && (
/* 353 */       e.getClickedBlock().getType().equals(Material.SIGN) || e.getClickedBlock().getType().equals(Material.SIGN_POST) || e.getClickedBlock().getType().equals(Material.WALL_SIGN))) {
/* 354 */       Sign s = (Sign)e.getClickedBlock().getState();
/* 355 */       if (s.getLine(0).equals(this.plugin.config.SignsPrefix)) {
/* 356 */         if (s.getLine(1).equals(this.plugin.config.JoinPrefix)) {
/* 357 */           if (p.getItemInHand().getType() != Material.AIR) {
/* 358 */             p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.JoinDenied);
/*     */             return;
/*     */           } 
/* 361 */           p.performCommand("kb join " + ChatColor.stripColor(s.getLine(2)));
/*     */         }
/* 363 */         else if (s.getLine(1).equals(this.plugin.config.StatsPrefix)) {
/* 364 */           p.performCommand("kb stats");
/*     */         }
/* 366 */         else if (s.getLine(1).equals(this.plugin.config.LeavePrefix)) {
/* 367 */           if (this.plugin.config.BungeeMode) {
/* 368 */             p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.CommandDisabled);
/*     */             return;
/*     */           } 
/* 371 */           if (this.plugin.game.contains(p.getName())) {
/* 372 */             p.getInventory().clear();
/* 373 */             this.plugin.getServer().getScheduler().scheduleSyncDelayedTask((Plugin)this.plugin, (Runnable)new BukkitRunnable() {
/*     */                   public void run() {
/* 375 */                     p.performCommand("kb leave");
/* 376 */                     p.updateInventory();
/*     */                   }
/* 378 */                 },  2L);
/*     */           } else {
/* 380 */             p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.NotInAGame);
/*     */           }
/*     */         
/* 383 */         } else if (s.getLine(1).equals(this.plugin.config.SoupPrefix)) {
/* 384 */           if (this.plugin.game.contains(p.getName())) {
/* 385 */             if (!s.getLine(2).isEmpty() && this.plugin.isNumber(s.getLine(2))) {
/* 386 */               int amount = Integer.valueOf(s.getLine(2)).intValue();
/* 387 */               if (this.plugin.getCoins(p) >= amount) {
/* 388 */                 int previousCoins = this.plugin.getCoins(p);
/* 389 */                 this.plugin.removeCoins(p, amount);
/* 390 */                 p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.PlayerLoseCoinsThroughCommand.replace("%coins%", String.valueOf(amount)));
/*     */                 try {
/* 392 */                   Scoreboard board = p.getScoreboard();
/* 393 */                   if (board.getObjective(DisplaySlot.SIDEBAR) == null || !board.getObjective(DisplaySlot.SIDEBAR).getDisplayName().equals(ChatColor.YELLOW + ChatColor.BOLD + ChatColor.UNDERLINE + "KitBattle")) {
/* 394 */                     this.plugin.createScoreboard(p);
/*     */                   } else {
/* 396 */                     Objective obj = board.getObjective(DisplaySlot.SIDEBAR);
/* 397 */                     board.resetScores(this.plugin.msgs.scoreboard_coins.replace("%coins%", String.valueOf(previousCoins)));
/* 398 */                     obj.getScore(this.plugin.msgs.scoreboard_coins.replace("%coins%", String.valueOf(this.plugin.getCoins(p)))).setScore(1);
/*     */                   } 
/* 400 */                 } catch (Exception x) {
/* 401 */                   x.printStackTrace();
/* 402 */                   this.plugin.logger.info("[KitBattle] Error has occured while creating/updating the player: " + p.getName() + " scoreboard!");
/*     */                 } 
/*     */               } else {
/* 405 */                 p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.NotEnoughCoins);
/*     */                 return;
/*     */               } 
/*     */             } 
/* 409 */             final Inventory inv = Bukkit.createInventory((InventoryHolder)p, 36, "Soup");
/* 410 */             for (int i = 0; i < 36; i++) {
/* 411 */               inv.addItem(new ItemStack[] { this.soup });
/*     */             } 
/* 413 */             p.openInventory(inv);
/*     */           } else {
/* 415 */             p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.NotInAGame);
/*     */           } 
/*     */         } 
/*     */         
/*     */         return;
/*     */       } 
/*     */     } 
/* 422 */     if (this.plugin.game.contains(p.getName()) && (
/* 423 */       e.getAction().equals(Action.RIGHT_CLICK_BLOCK) || e.getAction().equals(Action.RIGHT_CLICK_AIR))) {
/* 424 */       if (p.getItemInHand().getType().equals(Material.MUSHROOM_SOUP)) {
/* 425 */         if (p.getHealth() == p.getMaxHealth())
/* 426 */           return;  p.setHealth((p.getHealth() + 7.0D > p.getMaxHealth()) ? p.getMaxHealth() : (p.getHealth() + 7.0D));
/* 427 */         p.getItemInHand().setType(Material.BOWL);
/*     */         return;
/*     */       } 
/* 430 */       if (((PlayerData)this.plugin.playerData.get(p.getName())).getKit() == null) {
/* 431 */         if (isHolding(p, this.plugin.KitSelector)) {
/* 432 */           p.openInventory(((PlayerData)this.plugin.playerData.get(p.getName())).getMyKits());
/*     */           return;
/*     */         } 
/* 435 */         if (isHolding(p, this.plugin.ShopOpener)) {
/* 436 */           p.openInventory(((PlayerData)this.plugin.playerData.get(p.getName())).getShop());
/*     */           return;
/*     */         } 
/* 439 */         if (isHolding(p, this.plugin.KitUnlocker)) {
/* 440 */           if (this.plugin.openingKitunlocker.contains(p.getName())) {
/* 441 */             p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.AlreadyOpeningKitUnlocker);
/*     */             return;
/*     */           } 
/* 444 */           if (p.getItemInHand().getAmount() > 1) {
/* 445 */             p.getItemInHand().setAmount(p.getItemInHand().getAmount() - 1);
/*     */           } else {
/* 447 */             p.setItemInHand(new ItemStack(Material.AIR));
/*     */           } 
/* 449 */           if (((PlayerData)this.plugin.playerData.get(p.getName())).Shop.getContents()[0] == null) {
/* 450 */             p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.AlreadyUnlockedAllKits);
/* 451 */             ((PlayerData)this.plugin.playerData.get(p.getName())).kitUnlockers--;
/*     */             return;
/*     */           } 
/* 454 */           this.plugin.openingKitunlocker.add(p.getName());
/* 455 */           ((PlayerData)this.plugin.playerData.get(p.getName())).kitUnlockers--;
/* 456 */           p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.PlayerOpenKitUnlocker);
/* 457 */           Iterator<ItemStack> iterator = ((PlayerData)this.plugin.playerData.get(p.getName())).Shop.iterator();
/* 458 */           final ArrayList<ItemStack> possible = new ArrayList<ItemStack>();
/* 459 */           while (iterator.hasNext()) {
/* 460 */             ItemStack item = iterator.next();
/* 461 */             if (item != null) {
/* 462 */               possible.add(item);
/*     */             }
/*     */           } 
/* 465 */           final Inventory inv = Bukkit.createInventory((InventoryHolder)p, 54, ChatColor.LIGHT_PURPLE + ChatColor.MAGIC + "A" + ChatColor.DARK_RED + ChatColor.UNDERLINE + " Unlocking a kit " + ChatColor.LIGHT_PURPLE + ChatColor.MAGIC + "A");
/* 466 */           p.openInventory(inv);
/* 467 */           p.playSound(p.getLocation(), Sound.ITEM_PICKUP, 1.0F, 1.0F);
/* 468 */           for (int i = 0; i < 3; i++) {
/* 469 */             p.playEffect(p.getLocation().add(0.0D, i, 0.0D), Effect.ENDER_SIGNAL, 1);
/*     */           }
/* 471 */           final int targetSlot = this.random.nextInt(22) + 18;
/* 472 */           (new BukkitRunnable() {
/* 473 */               int slot = 0;
/*     */               public void run() {
/* 475 */                 if (this.slot > 0) inv.setItem(this.slot - 1, null); 
/* 476 */                 inv.setItem(this.slot, possible.get(listener.this.random.nextInt(possible.size())));
/* 477 */                 if (this.slot == targetSlot) {
/* 478 */                   listener.this.plugin.openingKitunlocker.remove(p.getName());
/* 479 */                   if (listener.this.plugin.playerData.containsKey(p.getName())) {
/* 480 */                     p.sendMessage(String.valueOf(listener.this.kb) + listener.this.plugin.msgs.PlayerWinKit.replace("%kit%", ChatColor.stripColor(inv.getItem(this.slot).getItemMeta().getDisplayName())));
/* 481 */                     ((PlayerData)listener.this.plugin.playerData.get(p.getName())).getShop().removeItem(new ItemStack[] { this.val$inv.getItem(this.slot) });
/* 482 */                     ((PlayerData)listener.this.plugin.playerData.get(p.getName())).myKits.addItem(new ItemStack[] { ((Kit)(listener.access$0(this.this$0)).Kits.get(ChatColor.stripColor(this.val$inv.getItem(this.slot).getItemMeta().getDisplayName().toLowerCase()))).getLogo() });
/* 483 */                     listener.this.plugin.organizeInventory(((PlayerData)listener.this.plugin.playerData.get(p.getName())).getShop());
/* 484 */                     for (Location loc : listener.this.getSurroundingLocations(p.getLocation())) {
/* 485 */                       listener.this.spawnFirework(loc);
/*     */                     }
/*     */                   } else {
/* 488 */                     (new BukkitRunnable() {
/*     */                         public void run() {
/* 490 */                           if ((listener.null.access$0(listener.null.this)).plugin.config.useMySQL) {
/*     */                             try {
/* 492 */                               Statement sql = (listener.null.access$0(listener.null.this)).plugin.connection.createStatement();
/* 493 */                               ResultSet generalData = sql.executeQuery("SELECT Kits FROM " + (listener.null.access$0(listener.null.this)).plugin.config.tableprefix + " WHERE " + (listener.null.access$0(listener.null.this)).plugin.playerNamePrefix + " = '" + (listener.null.access$0(listener.null.this)).plugin.target(p) + "';");
/* 494 */                               generalData.next();
/* 495 */                               String kits = generalData.getString("Kits");
/* 496 */                               kits = String.valueOf(kits) + ", " + ChatColor.stripColor(inv.getItem(listener.null.this.slot).getItemMeta().getDisplayName());
/* 497 */                               (listener.null.access$0(listener.null.this)).plugin.connection.prepareStatement("UPDATE " + (listener.null.access$0(listener.null.this)).plugin.config.tableprefix + " SET Kits='" + kits + "' WHERE " + (listener.null.access$0(listener.null.this)).plugin.playerNamePrefix + "='" + (listener.null.access$0(listener.null.this)).plugin.target(p) + "';").executeUpdate();
/* 498 */                             } catch (SQLException e) {
/* 499 */                               e.printStackTrace();
/*     */                             } 
/*     */                           } else {
/* 502 */                             List<String> kits = (listener.null.access$0(listener.null.this)).plugin.fileManager.getPlayersConfig().getStringList("Players." + (listener.null.access$0(listener.null.this)).plugin.target(p) + ".Kits");
/* 503 */                             kits.add(ChatColor.stripColor(inv.getItem(listener.null.this.slot).getItemMeta().getDisplayName()));
/* 504 */                             (listener.null.access$0(listener.null.this)).plugin.fileManager.getPlayersConfig().set("Players." + (listener.null.access$0(listener.null.this)).plugin.target(p) + ".Kits", kits);
/* 505 */                             (listener.null.access$0(listener.null.this)).plugin.fileManager.savePlayersConfig();
/*     */                           } 
/*     */                         }
/* 508 */                       }).runTaskAsynchronously((Plugin)listener.this.plugin);
/*     */                   } 
/* 510 */                   cancel();
/*     */                   return;
/*     */                 } 
/* 513 */                 this.slot++;
/* 514 */                 p.playSound(p.getLocation(), Sound.CLICK, 1.0F, 1.0F);
/*     */               }
/* 516 */             }).runTaskTimer((Plugin)this.plugin, 0L, 3L);
/*     */         } 
/*     */       } 
/*     */     } 
/*     */   }
/*     */ 
/*     */   
/*     */   @EventHandler
/*     */   public void onPlayerInteractWithEntity(PlayerInteractEntityEvent e) {
/* 525 */     if (e.getRightClicked().getType() != EntityType.PLAYER)
/* 526 */       return;  Player p = e.getPlayer();
/* 527 */     Player target = (Player)e.getRightClicked();
/* 528 */     if (!this.plugin.game.contains(p.getName()) || !this.plugin.game.contains(target.getName()))
/* 529 */       return;  if (!isHolding(p, this.plugin.Challenger))
/* 530 */       return;  if (((PlayerData)this.plugin.playerData.get(p.getName())).getKit() != null) {
/* 531 */       p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.MustHaveNoSelectedKitToChallenge);
/*     */       return;
/*     */     } 
/* 534 */     if (((PlayerData)this.plugin.playerData.get(target.getName())).getKit() != null) {
/* 535 */       p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.TargetMustHaveNoSelectedKitToChallenge.replace("%target%", target.getName()));
/*     */       return;
/*     */     } 
/* 538 */     if (this.plugin.challengeLocation1 == null || this.plugin.challengeLocation2 == null) {
/* 539 */       p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.NoChallengeLocationSet);
/*     */       return;
/*     */     } 
/* 542 */     if (this.plugin.Challenging.containsKey(target.getName()) && ((String)this.plugin.Challenging.get(target.getName())).equals(p.getName())) {
/* 543 */       this.plugin.Challenging.put(p.getName(), target.getName());
/* 544 */       startChallenge(p, target);
/* 545 */       p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.PlayerAcceptedChallenge.replace("%target%", target.getName()));
/* 546 */       target.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.TargetAcceptedChallenge.replace("%player%", p.getName()));
/*     */     } else {
/* 548 */       if (this.plugin.Challenging.containsKey(p.getName()) && ((String)this.plugin.Challenging.get(p.getName())).equals(target.getName())) {
/* 549 */         p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.SendChallengeDeny);
/*     */         return;
/*     */       } 
/* 552 */       this.plugin.Challenging.put(p.getName(), target.getName());
/* 553 */       p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.ChallengeSend.replace("%target%", target.getName()));
/* 554 */       target.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.ChallengeReceive.replace("%target%", p.getName()));
/*     */     } 
/*     */   }
/*     */   
/*     */   @EventHandler
/*     */   public void onPlayerClickInventory(InventoryClickEvent e) {
/* 560 */     Player p = (Player)e.getWhoClicked();
/* 561 */     if (!this.plugin.game.contains(p.getName()))
/* 562 */       return;  Inventory inv = e.getInventory();
/* 563 */     if (inv.getName().equals(ChatColor.RED + ChatColor.UNDERLINE + ChatColor.UNDERLINE + "My kits")) {
/* 564 */       e.setCancelled(true);
/* 565 */       ItemStack clicked = e.getCurrentItem();
/* 566 */       if (clicked == null || clicked.getType().equals(Material.AIR))
/* 567 */         return;  Kit kit = this.plugin.Kits.get(ChatColor.stripColor(clicked.getItemMeta().getDisplayName().toLowerCase()));
/* 568 */       if (kit == null)
/* 569 */         return;  if (!kit.isEnabled()) {
/* 570 */         p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.KitDisabled);
/*     */         return;
/*     */       } 
/* 573 */       if (kit.requirePermission && 
/* 574 */         !p.hasPermission(kit.permission)) {
/* 575 */         p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.NoPermissionForKit);
/*     */         
/*     */         return;
/*     */       } 
/* 579 */       ((PlayerData)this.plugin.playerData.get(p.getName())).setKit(kit);
/* 580 */       kit.giveItems(p);
/* 581 */       p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.PlayerSelectKit.replace("%kit%", kit.getName()));
/* 582 */       p.closeInventory();
/*     */       return;
/*     */     } 
/* 585 */     if (inv.getName().equals(ChatColor.RED + ChatColor.UNDERLINE + ChatColor.UNDERLINE + "Purchase more kits!")) {
/* 586 */       e.setCancelled(true);
/* 587 */       ItemStack clicked = e.getCurrentItem();
/* 588 */       if (clicked == null || clicked.getType().equals(Material.AIR))
/* 589 */         return;  Kit kit = this.plugin.Kits.get(ChatColor.stripColor(clicked.getItemMeta().getDisplayName().toLowerCase()));
/* 590 */       if (kit == null)
/* 591 */         return;  if (!kit.isEnabled()) {
/* 592 */         p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.KitDisabled);
/*     */         return;
/*     */       } 
/* 595 */       if (kit.requirePermission && 
/* 596 */         !p.hasPermission(kit.permission)) {
/* 597 */         p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.NoPermissionForKit);
/*     */         
/*     */         return;
/*     */       } 
/* 601 */       if (this.plugin.getCoins(p) >= kit.getPrice()) {
/* 602 */         Inventory select = Bukkit.createInventory((InventoryHolder)p, 9, ChatColor.DARK_RED + ChatColor.UNDERLINE + "Are you sure?");
/* 603 */         select.setItem(4, clicked);
/* 604 */         select.setItem(2, this.yes);
/* 605 */         select.setItem(6, this.no);
/* 606 */         p.openInventory(select);
/*     */       } else {
/* 608 */         p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.NotEnoughCoins);
/*     */       } 
/*     */       return;
/*     */     } 
/* 612 */     if (inv.getName().equals(ChatColor.DARK_RED + ChatColor.UNDERLINE + "Are you sure?")) {
/* 613 */       e.setCancelled(true);
/* 614 */       ItemStack clicked = e.getCurrentItem();
/* 615 */       if (clicked == null || clicked.getType().equals(Material.AIR))
/* 616 */         return;  if (clicked.equals(this.no)) {
/* 617 */         p.openInventory(((PlayerData)this.plugin.playerData.get(p.getName())).getShop());
/*     */         return;
/*     */       } 
/* 620 */       if (clicked.equals(this.yes)) {
/* 621 */         String kitName = ChatColor.stripColor(inv.getItem(4).getItemMeta().getDisplayName().toLowerCase());
/* 622 */         Kit kit = this.plugin.Kits.get(kitName);
/* 623 */         if (kit == null)
/* 624 */           return;  PlayerData data = this.plugin.playerData.get(p.getName());
/* 625 */         if (this.plugin.config.PurchaseableKitsArePermanent) {
/* 626 */           data.myKits.addItem(new ItemStack[] { kit.getLogo() });
/* 627 */           data.Shop.removeItem(new ItemStack[] { inv.getItem(4) });
/* 628 */           this.plugin.organizeInventory(data.Shop);
/* 629 */           p.openInventory(((PlayerData)this.plugin.playerData.get(p.getName())).getShop());
/*     */         } else {
/* 631 */           p.closeInventory();
/* 632 */           kit.giveItems(p);
/* 633 */           data.setKit(kit);
/* 634 */           p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.PlayerSelectKit.replace("%kit%", kit.getName()));
/*     */         } 
/* 636 */         int previousCoins = this.plugin.getCoins(p);
/* 637 */         this.plugin.removeCoins(p, kit.getPrice());
/*     */         try {
/* 639 */           Scoreboard board = p.getScoreboard();
/* 640 */           if (board.getObjective(DisplaySlot.SIDEBAR) == null || !board.getObjective(DisplaySlot.SIDEBAR).getDisplayName().equals(ChatColor.YELLOW + ChatColor.BOLD + ChatColor.UNDERLINE + "KitBattle")) {
/* 641 */             this.plugin.createScoreboard(p);
/*     */           } else {
/* 643 */             Objective obj = board.getObjective(DisplaySlot.SIDEBAR);
/* 644 */             board.resetScores(this.plugin.msgs.scoreboard_coins.replace("%coins%", String.valueOf(previousCoins)));
/* 645 */             obj.getScore(this.plugin.msgs.scoreboard_coins.replace("%coins%", String.valueOf(this.plugin.getCoins(p)))).setScore(1);
/*     */           } 
/* 647 */         } catch (Exception x) {
/* 648 */           x.printStackTrace();
/* 649 */           this.plugin.logger.info("[KitBattle] Error has occured while creating/updating the player: " + p.getName() + " scoreboard!");
/*     */         } 
/* 651 */         p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.PlayerPurchaseKit.replace("%kit%", kit.getName()).replace("%price%", String.valueOf(kit.getPrice())));
/*     */       } 
/*     */       return;
/*     */     } 
/* 655 */     if (inv.getName().equals(ChatColor.LIGHT_PURPLE + ChatColor.MAGIC + "A" + ChatColor.DARK_RED + ChatColor.UNDERLINE + " Unlocking a kit " + ChatColor.LIGHT_PURPLE + ChatColor.MAGIC + "A")) {
/* 656 */       e.setCancelled(true);
/*     */       return;
/*     */     } 
/*     */   }
/*     */   
/*     */   @EventHandler
/*     */   public void blockCommand(PlayerCommandPreprocessEvent e) {
/* 663 */     Player p = e.getPlayer();
/* 664 */     if (p.isOp())
/* 665 */       return;  if (this.plugin.game.contains(p.getName()) && 
/* 666 */       !this.plugin.config.allowedCommands.contains(e.getMessage().split(" ")[0].replace("/", "").toLowerCase())) {
/* 667 */       e.setCancelled(true);
/* 668 */       p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.CantUseCommands);
/*     */     } 
/*     */   }
/*     */ 
/*     */   
/*     */   @EventHandler
/*     */   public void onPlayerMoveEvent(PlayerMoveEvent e) {
/* 675 */     Player p = e.getPlayer();
/* 676 */     if (!this.plugin.game.contains(p.getName()))
/* 677 */       return;  if (e.getFrom().getBlockX() != e.getTo().getBlockX() || e.getFrom().getBlockZ() != e.getTo().getBlockZ()) {
/* 678 */       if (this.plugin.cantMove.contains(p.getName())) {
/* 679 */         p.teleport(e.getFrom());
/*     */       }
/* 681 */       else if (e.getTo().getBlock().getRelative(BlockFace.DOWN).getType().equals(Material.SPONGE)) {
/* 682 */         p.setVelocity(new Vector(0.0D, this.plugin.config.SpongeBoostUpwards, 0.0D));
/* 683 */         p.setFallDistance((float)-this.plugin.config.SpongeFallProtection);
/* 684 */         p.playSound(p.getLocation(), Sound.WITHER_SHOOT, 10.0F, 10.0F);
/*     */       } 
/*     */     }
/*     */   }
/*     */   
/*     */   @EventHandler
/*     */   public void onEntityDamage(EntityDamageEvent e) {
/* 691 */     if (e.getEntity().getType() != EntityType.PLAYER)
/* 692 */       return;  if (!e.getCause().equals(EntityDamageEvent.DamageCause.FALL))
/* 693 */       return;  if (this.plugin.game.contains(((Player)e.getEntity()).getName()) && !this.plugin.config.FallDamageEnabled) e.setCancelled(true); 
/*     */   }
/*     */   
/*     */   @EventHandler
/*     */   public void onSignChangeEvent(SignChangeEvent s) {
/* 698 */     if (!s.getLine(0).equalsIgnoreCase("[kb]"))
/* 699 */       return;  Player p = s.getPlayer();
/* 700 */     if (!p.hasPermission("kitbattle.createsigns")) {
/* 701 */       p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.nopermission);
/*     */       return;
/*     */     } 
/* 704 */     String line2 = s.getLine(1).toLowerCase();
/* 705 */     if (line2.equals("join") || line2.equals("leave") || line2.equals("soup") || line2.equals("stats") || line2.equals("top")) {
/* 706 */       if (line2.equals("join")) {
/* 707 */         String line3 = s.getLine(2).toLowerCase();
/* 708 */         if (this.plugin.maps.containsKey(line3)) {
/* 709 */           s.setLine(0, this.plugin.config.SignsPrefix);
/* 710 */           s.setLine(1, this.plugin.config.JoinPrefix);
/* 711 */           s.setLine(2, this.plugin.config.JoinLine3Color + s.getLine(2));
/* 712 */           p.sendMessage(String.valueOf(this.kb) + "You have created a join sign!");
/*     */         } else {
/* 714 */           p.sendMessage(String.valueOf(this.kb) + "Line 3 should be an existing map!");
/*     */         }
/*     */       
/* 717 */       } else if (line2.equals("leave")) {
/* 718 */         s.setLine(0, this.plugin.config.SignsPrefix);
/* 719 */         s.setLine(1, this.plugin.config.LeavePrefix);
/* 720 */         p.sendMessage(String.valueOf(this.kb) + "You have created a leave sign!");
/*     */       }
/* 722 */       else if (line2.equals("soup")) {
/* 723 */         s.setLine(0, this.plugin.config.SignsPrefix);
/* 724 */         s.setLine(1, this.plugin.config.SoupPrefix);
/* 725 */         p.sendMessage(String.valueOf(this.kb) + "You have created a soup sign!");
/*     */       }
/* 727 */       else if (line2.equals("stats")) {
/* 728 */         s.setLine(0, this.plugin.config.SignsPrefix);
/* 729 */         s.setLine(1, this.plugin.config.StatsPrefix);
/* 730 */         p.sendMessage(String.valueOf(this.kb) + "You have created a stats sign!");
/*     */       }
/* 732 */       else if (line2.equals("top")) {
/* 733 */         if (this.plugin.isNumber(s.getLine(2))) {
/* 734 */           int rank = Integer.valueOf(s.getLine(2)).intValue();
/* 735 */           if (rank < 1) {
/* 736 */             p.sendMessage(String.valueOf(this.kb) + "Line 3 must be a number higher than 0!");
/*     */             return;
/*     */           } 
/* 739 */           if (!this.plugin.fileManager.getSignsConfig().contains("Top." + rank)) {
/* 740 */             this.plugin.fileManager.getSignsConfig().set("Top." + rank + ".world", s.getBlock().getWorld().getName());
/* 741 */             this.plugin.fileManager.getSignsConfig().set("Top." + rank + ".x", Integer.valueOf(s.getBlock().getLocation().getBlockX()));
/* 742 */             this.plugin.fileManager.getSignsConfig().set("Top." + rank + ".y", Integer.valueOf(s.getBlock().getLocation().getBlockY()));
/* 743 */             this.plugin.fileManager.getSignsConfig().set("Top." + rank + ".z", Integer.valueOf(s.getBlock().getLocation().getBlockZ()));
/* 744 */             this.plugin.fileManager.saveSignsConfig();
/* 745 */             s.setLine(0, this.plugin.config.SignsPrefix);
/* 746 */             s.setLine(1, "Top");
/* 747 */             s.setLine(2, "#" + rank + " Waiting...");
/* 748 */             s.setLine(3, "(0)");
/* 749 */             this.plugin.fixUpdater();
/* 750 */             p.sendMessage(String.valueOf(this.kb) + "You have created a top sign!");
/*     */           } else {
/* 752 */             p.sendMessage(String.valueOf(this.kb) + "There is already a top sign that shows that rank!");
/*     */           } 
/*     */         } else {
/* 755 */           p.sendMessage(String.valueOf(this.kb) + "Line 3 must be a number!");
/*     */         } 
/*     */       } 
/*     */     } else {
/* 759 */       p.sendMessage(String.valueOf(this.kb) + "Line 2 must be one of those options join/leave/soup/stats/top!");
/*     */     } 
/*     */   }
/*     */   
/*     */   @EventHandler
/*     */   public void onPlayerChatEvent(AsyncPlayerChatEvent e) {
/* 765 */     Player p = e.getPlayer();
/* 766 */     if (this.plugin.game.contains(p.getName()) && 
/* 767 */       this.plugin.config.ShowRankInChat) {
/* 768 */       if (e.getMessage().contains("%")) {
/* 769 */         p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.CantUseCharacter);
/* 770 */         e.setCancelled(true);
/*     */         return;
/*     */       } 
/* 773 */       e.setFormat(String.valueOf(this.plugin.config.RanksPrefix.replace("%rank%", ((PlayerData)this.plugin.playerData.get(p.getName())).getRank().getName())) + e.getFormat());
/*     */     } 
/*     */   }
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public boolean checkRankUp(Player p, int previousRequiredExp) {
/* 781 */     PlayerData data = this.plugin.playerData.get(p.getName());
/* 782 */     if (data.getNextRank() != null && 
/* 783 */       data.getExp() >= data.getNextRank().getRequiredExp()) {
/* 784 */       String previousRank = data.getRank().getName();
/* 785 */       data.setRank(data.getNextRank());
/* 786 */       data.updateRankNumber();
/* 787 */       data.updateNextRank();
/* 788 */       p.sendMessage(String.valueOf(this.kb) + this.plugin.msgs.PlayerRankUp.replace("%rank%", data.getRank().getName()));
/* 789 */       for (String command : data.getRank().getExcutedCommands()) {
/* 790 */         Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), command.replaceAll("%player%", p.getName()));
/*     */       }
/* 792 */       if (this.plugin.config.BroadcastRankUp) {
/* 793 */         Bukkit.broadcastMessage(String.valueOf(this.kb) + this.plugin.msgs.PlayerRankUpPublicMessage.replace("%player%", p.getName()).replace("%rank%", data.getRank().getName()));
/*     */       } else {
/* 795 */         for (String s : this.plugin.game) {
/* 796 */           Bukkit.getPlayer(s).sendMessage(String.valueOf(this.kb) + this.plugin.msgs.PlayerRankUpPublicMessage.replace("%player%", p.getName()).replace("%rank%", data.getRank().getName()));
/*     */         }
/*     */       } 
/*     */       try {
/* 800 */         Scoreboard board = p.getScoreboard();
/* 801 */         if (board.getObjective(DisplaySlot.SIDEBAR) == null || !board.getObjective(DisplaySlot.SIDEBAR).getDisplayName().equals(ChatColor.YELLOW + ChatColor.BOLD + ChatColor.UNDERLINE + "KitBattle")) {
/* 802 */           this.plugin.createScoreboard(p);
/*     */         } else {
/* 804 */           Objective obj = board.getObjective(DisplaySlot.SIDEBAR);
/* 805 */           board.resetScores(this.plugin.msgs.scoreboard_rankname.replace("%rank%", previousRank));
/* 806 */           obj.getScore(this.plugin.msgs.scoreboard_rankname.replace("%rank%", data.getRank().getName())).setScore(-3);
/* 807 */           board.resetScores(this.plugin.msgs.scoreboard_nextrankname.replace("%requiredexp%", String.valueOf(previousRequiredExp)));
/* 808 */           if (data.getNextRank() == null) {
/* 809 */             board.resetScores(this.plugin.msgs.scoreboard_nextrank);
/*     */           } else {
/* 811 */             obj.getScore(this.plugin.msgs.scoreboard_nextrankname.replace("%requiredexp%", String.valueOf(data.getNextRank().getRequiredExp() - data.getExp()))).setScore(-5);
/*     */           } 
/*     */         } 
/* 814 */       } catch (Exception e) {
/* 815 */         e.printStackTrace();
/* 816 */         this.plugin.logger.info("[KitBattle] Error has occured while creating/updating the player: " + p.getName() + " scoreboard!");
/*     */       } 
/* 818 */       return true;
/*     */     } 
/*     */     
/* 821 */     return false;
/*     */   }
/*     */   
/*     */   public void startChallenge(final Player p, final Player target) {
/* 825 */     final String playerName = p.getName();
/* 826 */     final String targetName = target.getName();
/* 827 */     p.teleport(this.plugin.challengeLocation1);
/* 828 */     Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin)this.plugin, new Runnable() {
/*     */           public void run() {
/* 830 */             target.teleport(listener.this.plugin.challengeLocation2);
/*     */           }
/* 832 */         },  1L);
/* 833 */     this.plugin.cantMove.add(playerName);
/* 834 */     this.plugin.cantMove.add(targetName);
/* 835 */     for (String s : this.plugin.Fighting.keySet()) {
/* 836 */       Player x = Bukkit.getPlayer(s);
/* 837 */       x.hidePlayer(p);
/* 838 */       x.hidePlayer(target);
/* 839 */       p.hidePlayer(x);
/* 840 */       target.hidePlayer(x);
/*     */     } 
/* 842 */     Kit kit = this.plugin.Kits.get(this.plugin.config.ChallengeKit);
/* 843 */     kit.giveItems(p);
/* 844 */     kit.giveItems(target);
/* 845 */     ((PlayerData)this.plugin.playerData.get(playerName)).setKit(kit);
/* 846 */     ((PlayerData)this.plugin.playerData.get(targetName)).setKit(kit);
/* 847 */     BukkitTask runnable = (new BukkitRunnable() {
/*     */         boolean firstRun = true;
/* 849 */         int Seconds = 10;
/* 850 */         int nextWarn = 120;
/*     */         public void run() {
/* 852 */           if (this.Seconds == 0) {
/* 853 */             if (this.firstRun) {
/* 854 */               listener.this.plugin.cantMove.remove(playerName);
/* 855 */               listener.this.plugin.cantMove.remove(targetName);
/* 856 */               p.sendMessage(String.valueOf(listener.this.kb) + listener.this.plugin.msgs.ChallengeStart);
/* 857 */               target.sendMessage(String.valueOf(listener.this.kb) + listener.this.plugin.msgs.ChallengeStart);
/* 858 */               this.firstRun = false;
/* 859 */               this.Seconds += 121;
/*     */               
/*     */               return;
/*     */             } 
/* 863 */             p.sendMessage(String.valueOf(listener.this.kb) + listener.this.plugin.msgs.ChallengeTimeOut);
/* 864 */             target.sendMessage(String.valueOf(listener.this.kb) + listener.this.plugin.msgs.ChallengeTimeOut);
/* 865 */             listener.this.plugin.Fighting.remove(targetName);
/* 866 */             listener.this.plugin.Challenging.remove(targetName);
/* 867 */             listener.this.plugin.Fighting.remove(playerName);
/* 868 */             listener.this.plugin.Challenging.remove(playerName);
/* 869 */             listener.this.plugin.clearData(target);
/* 870 */             listener.this.plugin.clearData(p);
/* 871 */             ((PlayerData)listener.this.plugin.playerData.get(p.getName())).setKit(null);
/* 872 */             ((PlayerData)listener.this.plugin.playerData.get(target.getName())).setKit(null);
/* 873 */             target.teleport(listener.this.plugin.maps.get(((PlayerData)listener.this.plugin.playerData.get(targetName)).getMap()));
/* 874 */             p.teleport(listener.this.plugin.maps.get(((PlayerData)listener.this.plugin.playerData.get(playerName)).getMap()));
/* 875 */             listener.this.plugin.giveDefaultItems(target);
/* 876 */             listener.this.plugin.giveDefaultItems(p);
/* 877 */             cancel();
/*     */             
/*     */             return;
/*     */           } 
/* 881 */           if (this.firstRun) {
/* 882 */             p.sendMessage(String.valueOf(listener.this.kb) + listener.this.plugin.msgs.SecondsUntilChallengeBegin.replace("%seconds%", String.valueOf(this.Seconds)));
/* 883 */             target.sendMessage(String.valueOf(listener.this.kb) + listener.this.plugin.msgs.SecondsUntilChallengeBegin.replace("%seconds%", String.valueOf(this.Seconds)));
/*     */           }
/* 885 */           else if (this.Seconds == this.nextWarn) {
/* 886 */             if (this.Seconds == 120) {
/* 887 */               this.nextWarn = 60;
/*     */             }
/* 889 */             else if (this.Seconds == 60) {
/* 890 */               this.nextWarn = 30;
/*     */             }
/* 892 */             else if (this.Seconds == 30) {
/* 893 */               this.nextWarn = 15;
/*     */             }
/* 895 */             else if (this.Seconds == 15) {
/* 896 */               this.nextWarn = 10;
/*     */             }
/* 898 */             else if (this.Seconds == 10) {
/* 899 */               this.nextWarn = 5;
/*     */             } else {
/* 901 */               this.nextWarn = this.Seconds - 1;
/*     */             } 
/* 903 */             p.sendMessage(String.valueOf(listener.this.kb) + listener.this.plugin.msgs.ChallengeTimeWillRunOut.replace("%seconds%", String.valueOf(this.Seconds)));
/* 904 */             target.sendMessage(String.valueOf(listener.this.kb) + listener.this.plugin.msgs.ChallengeTimeWillRunOut.replace("%seconds%", String.valueOf(this.Seconds)));
/*     */           } 
/*     */           
/* 907 */           this.Seconds--;
/*     */         }
/* 909 */       }).runTaskTimer((Plugin)this.plugin, 0L, 20L);
/* 910 */     this.plugin.Fighting.put(playerName, runnable);
/* 911 */     this.plugin.Fighting.put(targetName, runnable);
/*     */   }
/*     */   
/*     */   public void removeFromChallenge(Player p) {
/* 915 */     this.plugin.fixVisiblity(p);
/* 916 */     this.plugin.cantMove.remove(p.getName());
/* 917 */     this.plugin.clearData(p);
/* 918 */     ((PlayerData)this.plugin.playerData.get(p.getName())).setKit(null);
/* 919 */     p.teleport(this.plugin.maps.get(((PlayerData)this.plugin.playerData.get(p.getName())).getMap()));
/* 920 */     this.plugin.giveDefaultItems(p);
/* 921 */     ((BukkitTask)this.plugin.Fighting.get(p.getName())).cancel();
/* 922 */     this.plugin.Fighting.remove(p.getName());
/* 923 */     this.plugin.Challenging.remove(p.getName());
/*     */   }
/*     */   
/*     */   public ArrayList<Location> getSurroundingLocations(Location loc) {
/* 927 */     ArrayList<Location> locations = new ArrayList<Location>();
/* 928 */     locations.add(loc.clone().add(-1.0D, 0.0D, 0.0D));
/* 929 */     locations.add(loc.clone().add(0.0D, 0.0D, 1.0D));
/* 930 */     locations.add(loc.clone().add(0.0D, 0.0D, -1.0D));
/* 931 */     locations.add(loc.clone().add(1.0D, 0.0D, 0.0D));
/* 932 */     return locations;
/*     */   }
/*     */   
/*     */   public void spawnFirework(Location loc) {
/* 936 */     Firework firework = (Firework)loc.getWorld().spawn(loc, Firework.class);
/* 937 */     FireworkMeta fwm = firework.getFireworkMeta();
/* 938 */     FireworkEffect.Type type = FireworkEffect.Type.BALL;
/* 939 */     FireworkEffect effect = FireworkEffect.builder().flicker(this.random.nextBoolean()).withColor(Color.fromBGR(this.random.nextInt(256), this.random.nextInt(256), this.random.nextInt(256))).withFade(Color.fromBGR(this.random.nextInt(256), this.random.nextInt(256), this.random.nextInt(256))).with(type).trail(this.random.nextBoolean()).build();
/* 940 */     fwm.addEffect(effect);
/* 941 */     fwm.setPower(0);
/* 942 */     firework.setFireworkMeta(fwm);
/*     */   }
/*     */ 
/*     */   
/* 946 */   public boolean isHolding(Player p, ItemStack item) { return (p.getItemInHand().getType().equals(item.getType()) && p.getItemInHand().getItemMeta().getDisplayName().equals(item.getItemMeta().getDisplayName())); }
/*     */ }


/* Location:              C:\Users\韩烨均\Documents\Tencent Files\133280410\FileRecv\KitBattle.jar!\me\wazup\kitbattle\listener.class
 * Java compiler version: 5 (49.0)
 * JD-Core Version:       1.1.2
 */